package ishacrm.client;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.InlineHTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class MemberSummary extends Composite {

	private static MemberSummaryUiBinder uiBinder = GWT
			.create(MemberSummaryUiBinder.class);

	interface MemberSummaryUiBinder extends UiBinder<Widget, MemberSummary> {
	}

	public MemberSummary(ContactDetailProp contactDetailProp, boolean showDetail) {
		initWidget(uiBinder.createAndBindUi(this));

		name.setInnerText(contactDetailProp.name);

		if (showDetail) {

			if (contactDetailProp.email != null)
				email.setText(contactDetailProp.email);

			if (contactDetailProp.phones != null)
				phone.setText(contactDetailProp.phones);

			if (contactDetailProp.centers != null)
				centers.setInnerText(contactDetailProp.centers);

			labels.add(getLabelHtmlPanel(contactDetailProp.labels));
		}
	}

	public MemberSummary() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	HTMLPanel getLabelHtmlPanel(List<String> labels) {
		HTMLPanel htmlPanel = new HTMLPanel("");

		for (String label : labels) {
			InlineHTML html = new InlineHTML(label);
			html.addStyleName("ishaCRMLabel");
			htmlPanel.add(html);
		}

		return htmlPanel;
	}

	@UiField SpanElement name;
	@UiField Label email;
	@UiField Label phone;
	@UiField HTMLPanel labels;
	@UiField SpanElement centers;
}
